import api from '../../api';
import { message } from 'antd';
import { isZiGuanEvir } from '../../utils/commonFunc';

export default {
  namespace: 'bondHistoricalDealInfoM',

  state: {
    loading: true,
  },
  effects: {
    //获取表格数据
    *getTableData({ payload, callback }, { call, put }) {
      let response;
      let isZG = false;
      // 判断当前环境是不是资管
      let temp = isZiGuanEvir();
      console.log(temp);
      if (!!temp && temp['iv-user']) isZG = true;
      if (isZG) {
        payload.userId = temp['iv-user'];
        response = yield call(api.bondHistoricalDealInfo.getTableDataZG, payload);
      } else {
        response = yield call(api.bondHistoricalDealInfo.getTableData, payload);
      }
      if (response && response.code === 0) {
        callback('success', response.data);
      } else {
        callback('fail');
        message.error(response.msg || '获取债券历史交易数据失败');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
